home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / rss / chesc.c next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  3.0 KB  |  120 lines

  1. #ifndef MSDOS
  2.  
  3. /*                              C H E S C . C
  4.  
  5. */
  6.  
  7. #include "../rss/icrssdef.h"
  8.  
  9. static char
  10.     near hexnumbers[] = "0123456789abcdef";
  11.  
  12. static int near atox (char *string, int *n)
  13. {
  14.     register unsigned
  15.         i,
  16.         ch;
  17.     unsigned
  18.         retval;
  19.  
  20.     if (*string == 'x')
  21.     {
  22.         (*n)++;                             /* 'x' processed */
  23.         string++;                           /* and skipped */
  24.         if (!sscanf(string, "%3x", &retval))/* No hex char value ? */
  25.             return (-1);                    /* Flag no hex digit */
  26.  
  27.         retval &= 0xff;                     /* Compute char value */
  28.         ch = 16;                            /* Radix setting */
  29.     }
  30.     else if (sscanf(string, "%3o", &retval))/* octal value ? */
  31.     {
  32.         if (retval >= 0x100)                /* Octal yields too big a value ? */
  33.             return (-2);                    /* Return it */
  34.  
  35.         ch = 8;                             /* Radix setting */
  36.     }
  37.     else                                    /* Return character unchanged */
  38.     {
  39.         (*n)++;                             /* ch */
  40.         return (*string);
  41.     }
  42.  
  43.     hexnumbers[ch] = 0;                     /* Set hex conversion */
  44.  
  45.     for (i = 3; i--;)                       /* At most 3 digits */
  46.     {
  47.         ch = *string++;                     /* Fetch char */
  48.  
  49.         ch = tolower(ch);                   /* Convert to lower */
  50.  
  51.         if (!strchr (hexnumbers, ch))       /* No more number character ? */
  52.             break;                          /* Leave the loop */
  53.  
  54.         (*n)++;                             /* eat char. */
  55.     }
  56.  
  57.     hexnumbers[8] = '8';                    /* restore the hex-string */
  58.  
  59.     return (retval);                        /* Returnvalue */
  60. }
  61.  
  62. int chesc(char *string, int *n)
  63. {
  64.     register int
  65.         c;
  66.  
  67.     if (!(c = *string++))
  68.     {
  69.         *n = 0;
  70.         return (0);                         /* return 0 at end of string */
  71.     }
  72.  
  73.     if (c != '\\')                          /* No escape char ? */
  74.     {
  75.         *n = 1;
  76.         return (c);                         /* Return the character */
  77.     }
  78.  
  79.     *n = 2;                                 /* 1 (escape) char processed */
  80.                                             /* count 1 extra char to follow */
  81.  
  82.     switch (c = *string++)                  /* fetch next char */
  83.     {
  84.         case 'n':
  85.             return ('\n');                  /* newline */
  86.  
  87.         case 't':
  88.             return ('\t');                  /* (etc.) */
  89.  
  90.         case 'v':
  91.             return ('\v');
  92.  
  93.         case 'b':
  94.             return ('\b');
  95.  
  96.         case 'r':
  97.             return ('\r');
  98.  
  99.         case 'f':
  100.             return ('\f');
  101.  
  102.         case 'a':
  103.             return ('\a');
  104.  
  105.         case '\'':
  106.             return ('\'');
  107.  
  108.         case '"':
  109.             return ('"');
  110.  
  111.         case '\\':
  112.             return ('\\');
  113.  
  114.         default:
  115.             (*n)--;                         /* extra char not yet done */
  116.             return (atox (string - 1, n));
  117.     }
  118. }
  119. #endif
  120.